export default {
  getInfo(state) {
    getUserInfo((res) => {
      state.commit('setUserInfo', res.data)
    })
  },
  // 获取购物车数据
  getCarDataList(state) {
    getCarList().then((res) => {
      if (res.status === 0) {
        const list = res.data
        let count = 0
        list.forEach((ele) => {
          count += ele.count
          ele.checked = false
        })
        state.commit('setBadgeCount', count)
        state.commit('setCarList', list)
      }
    })
  },

  // 处理购物车单选
  changeSingleChecked(state) {
    // 全选状态判断
    let checked = true
    state.getters.getCarData.forEach((item) => {
      if (!item.checked) {
        checked = false
        return
      }
    })
    state.commit('setAllChecked', checked)
  },
}
